<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="./css/gameState.css">
    <title>2021少数民族传统体育竞技</title>
</head>

<body>
    <div class="layout">
        <img src="http://qrwbtqqjh.hn-bkt.clouddn.com/game1_32.png" alt="" class="bg-img">
        <img src="./img/back_btn.png" alt="" class="back-btn">
        <div class="state-text-box">
            <p>闯关成功!</p>
            <p class="success-text">恭喜闯过第一关</p>
        </div>
        <p class="score"></p>
        <p class="fail-text">未达到通关分数</p>
        <img src="./img/again_icon.png" alt="" class="icon again">
        <img src="./img/next_icon.png" alt="" class="icon next">
        <img src="./img/share_btn.png" alt="" class="icon share">
        <img src="./img/skill_icon.png" alt="" class="icon explain">
        <div class="treasure-box">
            <p class="desc-text">点击开启通关宝藏</p>
            <img src="./img/yellow_box.png" alt="" class="yellow-box">
        </div>
    </div>
    <div class="tips-box">
        <p>分享游戏给5个朋友</p>
        <p>可以直接通关获取一次抽奖次数</p>
    </div>

    <script src="./js/jquery.js"></script>
    <script src="./js/arctext.js"></script>
    <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="./js/request.js"></script>
    <script>
        (function ($) {
            $.getUrlParam = function (name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        })(jQuery);
        let score = $.getUrlParam('score'); //游戏结束时的得分
        let passScore, //通关所需要的分数
            success //游戏是否通关
        $('.score').text(score)
        request('refresh_settings/', {
            zm_token: localStorage.user_token,
            _zm_post_type: 'ajax'
        }).then(res => {
            // alert(JSON.stringify(res.rsm),'地址:refresh_settings/',)
            let key = localStorage.progress
            let result = res.rsm
            passScore = result[key == 1 ? 'tree_score' : key == 2 ? 'jump_score' : 'dance_score']
            console.log(`游戏得分${score},通关分数${passScore},是否通关->${(score | 0) >= (passScore | 0) ? '是' : '否'}`);
            if ((score | 0) >= (passScore | 0)) {
                $('.fail-text').hide()
                $('.treasure-box').show()
                // 记得清除
                if (locMemory.localStorage.getItem(`game${localStorage.getItem('progress')}`).luck) {
                    $('.treasure-box').hide()
                }
                $('.success-text').text(
                    `恭喜闯过第${(localStorage.getItem('progress') | 0) == 1 ? '一' : (localStorage.getItem('progress') | 0) == 2 ? '二' : '三'}关`
                )
                // --------------
            } else {
                $('.share').show()
                $('.state-text-box').html(`<p class="fail-text">闯关失败</p>`)
                $('.score').css('margin-bottom', '0.15rem')
                $('.bg-img').attr('src', 'http://qrwbtqqjh.hn-bkt.clouddn.com/game1_31.png')
                $('.bg-img').addClass('fail-img')
                $('.score').css('color', '#715857')
                $('.treasure-box').hide()
                $('.next').hide()
            }
        })

        // 记得清除
        let gameState = JSON.parse(localStorage.getItem(`game${localStorage.getItem('progress')}`))
        if ((localStorage.getItem('progress') | 0) < 3) {
            if (gameState.active) {
                $('.next').show()
                $('.share').hide()
            }
        } else {
            $('.next').hide()
            $('.share').hide()
        }

        $('.back-btn').on('click', function () {
            location.href = 'http://youxi.haiqikj.com/chooseGame.html'
        })
        $(".desc-text").arctext({
            radius: 120
        })




        // 记得清除
        let progress = Number(locMemory.localStorage.getItem('progress'))
        // --------------

        $('.again').on('click', function () {
            location.href = `game${locMemory.localStorage.getItem('progress')}.html`
        })

        $('.next').on('click', function () {
            location.href = `game${(progress | 0) + 1}.html`
            // 记得清除
            locMemory.localStorage.setItem('progress', progress == 3 ? 3 : (progress | 0) + 1)
            locMemory.localStorage.setItem('progress', progress == 3 ? 3 : (progress | 0) + 1)
        })

        // 抽奖
        $('.yellow-box').on('click', function () {
            // 记得清除
            let game = locMemory.localStorage.getItem(`game${locMemory.localStorage.getItem('progress')}`)
            game.luck = true
            game = JSON.stringify(game)
            localStorage.setItem(`game${localStorage.getItem('progress')}`, game)
            let key = locMemory.localStorage.getItem('progress')
            // -----------
            request('lottery/', {
                zm_token: localStorage.user_token,
                _zm_post_type: 'ajax',
                lottery_type: key == 1 ? 'tree_lottery' : key == 2 ? 'jump_lottery' : 'dance_lottery'
            }).then(res => {
                location.href =
                    `./luckState.html?state=${res.errno == 200}&amount=${res.rsm.amount || 0}`
            })
        })

        $('.explain').on('click', function () {
            location.href = 'http://youxi.haiqikj.com/explain.html'
        })
        $('.share').on('click', function () {
            // $('.tips-box').show()
            location.href = 'http://youxi.haiqikj.com/share.html'
        })
        $('.tips-box').on('click', function () {
            $(this).hide()
        })
        request('get_share_sign/', {
            zm_token: localStorage.user_token,
            _zm_post_type: 'ajax',
            url: location.href
        }).then(res => {
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: res.rsm.appId, // 必填，公众号的唯一标识
                timestamp: res.rsm.timestamp, // 必填，生成签名的时间戳
                nonceStr: res.rsm.nonceStr, // 必填，生成签名的随机串
                signature: res.rsm.signature, // 必填，签名
                jsApiList: ['onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'onMenuShareQZone',
                    'onMenuShareTimeline',
                    'updateAppMessageShareData',
                    'hideOptionMenu',
                    'showOptionMenu',
                    'hideMenuItems',
                    'showMenuItems',
                    'hideAllNonBaseMenuItem',
                    'showAllNonBaseMenuItem',
                ] // 必填，需要使用的JS接口列表
            });
            wx.ready(function () { //需在用户可能点击分享按钮前就先调用
                wx.hideAllNonBaseMenuItem();
            });
        })
    </script>

</body>

</html>